const app = getApp()
const db = wx.cloud.database({})


Page({
  data:{
    selectedQsid:'this is the pickedID',
    selectedTiltle:'',
    openid:'',
    querys:[],
    windowWidth:0,
    windowHeight:0
  },
  onLoad: function () {
    wx.cloud.callFunction({
      name:'getOpenId',
    }).then(res=>{
      console.log("查询到的openid为"+res.result.openid)
      this.setData({
        openid:res.result.openid
      })
      console.log("data"+this.data.openid)
      console.log("tis"+this.openid)
      db.collection("questions").where({
        _openid:this.data.openid
      }).get().then(res=>{
        console.log("查询得到的问卷有： ")
        console.log(res.data)
        this.setData({
          querys:res.data
        })
      })
    })
    console.log(this.data.openid)
    
  },
  onReady:function () {
    wx.getSystemInfo({
      success:res=>{
        this.setData({
          windowWidth:res.windowWidth,
          windowHeight:res.windowHeight
        })
      }
    })
  },
  navigateToStats:function(e){
    
    console.log("点击的按钮id："+e.currentTarget.dataset.value)
    this.setData({
      selectedQsid:e.currentTarget.dataset.value
    })
    db.collection("questions").where({
      q_id:this.data.selectedQsid
    }).get({
      success:(res)=>{
        this.setData({
          selectedTiltle:res.data[0].name
        })
        wx.navigateTo({
          url: '../stat/statistics?selectedQsid='+this.data.selectedQsid+'&selectedTitle='+this.data.selectedTiltle
        })
      }
      
    } )

    
  }
})
